// 暂时性代码，兼容layout模块中，某些字段语义不规范、错误的问题
// 编写日期 2022-8-25


function layoutCompatible(componentsName:string, option:any) {
	let _option = { ...option }
	switch (componentsName) {
		case 'account':
		case 'boutiqueRecommend':
		case 'collage':
		case 'goodsBanner':
		case 'magicCube':
		case 'porcelain':
		case 'seckill':
		case 'userInfo':
		case 'video':
			if (_option.goodsRadiusTop) {
				_option.radiusTop = _option.goodsRadiusTop
				delete _option.goodsRadiusTop
			}
			if (_option.goodsRadiusBottom) {
				_option.radiusBottom = _option.goodsRadiusBottom
				delete _option.goodsRadiusBottom
			}
			break
		case 'businessList':
			if (_option.goodsRadiusTop) {
				_option.radiusTop = _option.goodsRadiusTop
				delete _option.goodsRadiusTop
			}
			if (_option.goodsRadiusBottom) {
				_option.radiusBottom = _option.goodsRadiusBottom
				delete _option.goodsRadiusBottom
			}
			if (_option.storeNameColor) {
				_option.goodsNameColor = _option.storeNameColor
				delete _option.storeNameColor
			}
			if (_option.goodsMargin) {
				_option.storeMargin = _option.goodsMargin
				delete _option.goodsMargin
			}
			break
		case 'fixedButton':
			_option.list = option.list.map(item => {
				let data = {
					url: item.url,
					link: item.link,
					type: item.type
				}
				if (item.isDefault || item.isDefault === 0) {
					data.type = item.isDefault
				}
				return data
			})
			if (_option.goodsRadiusTop) {
				_option.radiusTop = _option.goodsRadiusTop
				delete _option.goodsRadiusTop
			}
			if (_option.goodsRadiusBottom) {
				_option.radiusBottom = _option.goodsRadiusBottom
				delete _option.goodsRadiusBottom
			}
			break
		case 'orderIcon':
			if (!_option.titleList) {
				_option.titleList = []
			}
			break
		case 'commonlyIcon':
			if (_option.titleShow !== false) {
				_option.titleShow = true
			}
			if (_option.rowNumber !== 5) {
				_option.rowNumber = 4
			}

			break
		case 'purchase':
			if (!_option.layoutType) {
				_option.layoutType = 1
			}
			if (!_option.backgroundColor) {
				_option.backgroundColor = 'rgba(255, 255, 255, 1)'
			}
			if (_option.showHomeIcon !== false) {
				_option.showHomeIcon = true
			}

			if (!_option.homeTextColor) {
				_option.homeTextColor = 'rgba(102, 102, 102, 1)'
			}
			if (_option.showContactIcon !== false) {
				_option.showContactIcon = true
			}

			if (!_option.contactTextColor) {
				_option.contactTextColor = 'rgba(102, 102, 102, 1)'
			}
			
			if (_option.showCollectIcon !== false) {
				_option.showCollectIcon = true
			}

			if (!_option.contactTextColor) {
				_option.contactTextColor = 'rgba(102, 102, 102, 1)'
			}
			if (_option.showCartButton !== false) {
				_option.showCartButton = true
			}

			if (!_option.cartButtonRadius && _option.cartButtonRadius !== 0) {
				_option.cartButtonRadius = 20
			}
			if (_option.showBuyButton !== false) {
				_option.showBuyButton = true
			}

			if (!_option.buyButtonRadius && _option.buyButtonRadius !== 0) {
				_option.buyButtonRadius = 20
			}
			break
	}

	return _option
}

export default layoutCompatible
